﻿package net.wangit.dev.enumeration;

import net.wangit.context.ActionContext;
import net.wangit.dev.DomainAction;
import net.wangit.dev.ObjectChecker;
import net.wangit.jdbc.DB;
import net.wangit.user.privilege.DataPrivilegeCache;
import net.wangit.util.Checker;
import net.wangit.view.enumeration.EnumerationCache;
import net.wangit.view.enumeration.EnumerationConfigCache;

public class DeleteEnumerationAction extends DomainAction {

	private static final String SQL_CHECK = "select l from ENUMCONFIG where enumid=?";
	private static final String SQL_CONFIG = "delete from ENUMCONFIG where enumid=?";
	private static final String SQL_ENUMERATION = "delete from ENUM where enumid=?";

	public DeleteEnumerationAction() {
	}

	public void doAction(DB db, ActionContext ac) throws Exception {
		String eid = ac.getRequestParameter("eid");
		if (!Checker.isEmpty(eid)) {
			net.wangit.MapList list = db.query(
					DeleteEnumerationAction.SQL_CHECK, eid, 2);
			if (ObjectChecker.invalid(ac, list, "l"))
				return;
			db.execute(DeleteEnumerationAction.SQL_CONFIG, eid, 2);
			db.execute(DeleteEnumerationAction.SQL_ENUMERATION, eid, 2);
			EnumerationCache.clear(domain, eid);
			EnumerationConfigCache.clear(domain, eid);
			DataPrivilegeCache.clear(domain, "4", eid);
			EnumerationReferenceUtil.update(db, domain, eid, "");
		}
	}
}
